package cn.play.cardgame.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import butterknife.ButterKnife;
import butterknife.InjectView;
import cn.play.cardgame.R;
import cn.play.cardgame.constant.Constant;
import cn.play.cardgame.util.ImageUtil;

public class ProgressPanel extends LinearLayout {
	@InjectView(R.id.progress_turn)
	ImageView mImageViewTurn;
	@InjectView(R.id.progress_bureau)
	ImageView mImageViewBureau;
	private Context mContext;
	private int turn = 1;
	private int bureau = 1;

	public ProgressPanel(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		mContext = context;
		initViews();
	}

	public ProgressPanel(Context context, AttributeSet attrs) {
		this(context, attrs, 0);
	}

	public ProgressPanel(Context context) {
		this(context, null);
	}

	private void initViews() {
		LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
				LinearLayout.LayoutParams.WRAP_CONTENT,
				LinearLayout.LayoutParams.WRAP_CONTENT);

		View view = View.inflate(mContext, R.layout.progress_panel, null);
		ButterKnife.inject(this, view);

		this.addView(view, params);
	}

	@SuppressWarnings("deprecation")
	private void setTurn(String turn) {
		mImageViewTurn.setBackgroundDrawable(ImageUtil.getInstance()
				.bitmapToDrawable(mContext, ImageUtil.getProgressMapping(),
						turn));
	}

	@SuppressWarnings("deprecation")
	private void setBureau(String bureau) {
		mImageViewBureau.setBackgroundDrawable(ImageUtil.getInstance()
				.bitmapToDrawable(mContext, ImageUtil.getProgressMapping(),
						bureau));
	}

	public int getTurn() {
		return turn;
	}

	public void setTurn(int turn) {
		this.turn = turn;
		Constant.TURN = turn;
		setTurn(String.format("%03d", turn));
	}

	public int getBureau() {
		return bureau;
	}

	public void setBureau(int bureau) {
		this.bureau = bureau;
		Constant.BUREAU = bureau;
		setBureau(String.format("%03d", bureau));
	}

	public void addTurn() {
		this.turn = this.turn + 1;
	}
	
	public void addBureau() {
		this.bureau = this.bureau + 1;
	}

}
